22 template <class T
> string
toStr(const T
&x
){ stringstream s
; s
<< x
; return s
.str(); }
23 template <class T
> int toInt(const T
&x
){ stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
24 template <class T
> int Size(const T
&x
){ return (int)x
.size(); }
26 #define For(i, a, b) for (int i=(a); i<(b); ++i)
27 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
28 #define D(x) cout << #x " is " << x << endl
30 typedef unsigned long long Int
;
31 const int BUFSIZE
= 128;
40 node(bool e
) : end(e
) {
46 if (n
== NULL
) return;
47 clean(n
->left
); clean(n
->right
);
52 Int
f(string s
, node
* n
){
53 Int left
= 0, right
= 0;
55 left
= f(s
+ "0", n
->left
);
57 if (n
->right
!= NULL
){
58 right
= f(s
+ "1", n
->right
);
61 Int x
= ((1ULL) << (M
- s
.size())) - 1;
62 if (M
== 64 && s
.size() == 0){
65 ans
[s
] = x
- left
- right
+ 1;
73 return ret
+ left
+ right
;
78 while (cin
>> n
>> M
&& n
&& M
){
79 vector
<string
> prefixes(n
+1, "");
82 prefixes
[i
].resize(prefixes
[i
].size()-1); //delete *
86 for (int i
=0; i
<(1<<M
); ++i
){
88 for (int k
=0; k
<M
; ++k
){
89 char c
= !!(i
& (1 << k
)) + '0';
92 int ibest
= -1, lenbest
= INT_MIN
;
93 for (int j
=0; j
<prefixes
.size(); ++j
){
94 string prefix
= prefixes
[j
];
96 if (s
.find(prefix
) == 0){
97 //cout << s << " starts with " << prefix << endl;
98 if (lenbest
< Size(prefix
)){
100 lenbest
= prefix
.size();
104 ans
[prefixes
[ibest
]]++;
113 q
.resize(q
.size()-1);
114 cout
<< ans
[q
] << endl
;